﻿using System;
using System.Linq;
using System.ServiceProcess;
using System.Threading;
using Biz.EF.Gateway.Total;
using Biz.EF.Platform.Gxt;
using Biz.Process;
using Hjt212Parser;
using log4net;

namespace Biz
{
    public partial class BizProcessor : ServiceBase
    {
        private static ILog Log = LogManager.GetLogger(typeof(BizProcessor));
        int milliSeconds = 100;
        public BizProcessor()
        {
            InitializeComponent();
        }
        //test
        public void Main()
        {
            OnStart(null);
        }
        protected override void OnStart(string[] args)
        {
            //启动各路线程
            new Thread(UplineCmd).Start();          
            new Thread(DownlineCmd).Start();
            Log.Info("Yangkou-Total-Processor was started!");
        }
        protected override void OnStop()
        {
            Log.Error( new Exception("Yangkou-Total-Processor was stoped!"));
        }

        private void UplineCmd(object state)
        {
            while (true)
            {
                try
                {
                    CommonProcessor.Process();
                }
                catch (Exception ex)
                {
                    Log.Error( ex);
                }
                finally
                {
                    ThreadUtil.Sleep(milliSeconds);
                }
            }
            // ReSharper disable once FunctionNeverReturns
        }
      
        private void DownlineCmd(object state)
        {
            while (true)
            {
                try
                {
                    ProcessorDownlineCmd.GenDownlineCmd();
                }
                catch (Exception ex)
                {
                    Log.Error( ex);
                }
                finally
                {
                    ThreadUtil.Sleep(1000);
                }
            }
            // ReSharper disable once FunctionNeverReturns
        }

    }
}
